﻿using System;
using System.Collections;
using System.Collections.Generic;
using KamLib;
using Ext.Net;

namespace WebPoligon.Views.View1
{

    [UilID("V1")]
    public class rView1
    {

        public class Page : UilController
        {
            public override UilController GetPartController(IUilViewPart part)
            {
                return
                    part.Name == "tab1" ? Context.New<Tab1>() :
                    part.Name == "g2" ? Context.GetController(new UilKey { CTID = "V1.Grid1" }) :
                    null;
            }
        }


        public class Tab1 : UilController
        {
            public override UilController GetPartController(IUilViewPart part)
            {
                return
                    part.Name == "g1" ? Context.New<Grid1>() :
                    part.Name == "g1d" ? Context.New<Grid1D>() :
                    null;
            }

            [UilMethod]
            public void Hello1()
            {

            }
        }


        public class Grid1 : UilController, IUilEntitiesSource
        {

            #region IUilEntitiesSource Members

            static readonly DbFieldID.List _KeyFields = new DbFieldID.List("ID");
            public DbFieldID.List KeyFields { get { return _KeyFields; } }
            public DbFieldID.List SortFields { get { return null; } }
            public DbFieldID.List GroupFields { get { return null; } }

            public bool? CanInsert { get { return false; } }
            public bool? CanEdit { get { return false; } }
            public bool? CanDelete { get { return false; } }
            public bool? IsLocal { get { return null; } }
            public int? PageSize { get { return 10; } }

            #endregion
            

            public IEnumerable GetData(QueryArgs e)
            {
                return new[]
                {
                    new { ID = 1, Name = "Name  1" },
                    new { ID = 2, Name = "Name  2" },
                    new { ID = 3, Name = "Name  3" },
                    new { ID = 4, Name = "Name  4" },
                    new { ID = 5, Name = "Name  5" },
                    new { ID = 6, Name = "Name  6" },
                    new { ID = 7, Name = "Name  7" },
                    new { ID = 8, Name = "Name  8" },
                    new { ID = 9, Name = "Name  9" },
                    new { ID = 10, Name = "Name 10" },
                    new { ID = 21, Name = "Name 21" },
                    new { ID = 22, Name = "Name 22" },
                    new { ID = 23, Name = "Name 23" },
                    new { ID = 24, Name = "Name 24" },
                    new { ID = 25, Name = "Name 25" },
                    new { ID = 26, Name = "Name 26" },
                    new { ID = 27, Name = "Name 27" },
                    new { ID = 28, Name = "Name 28" },
                    new { ID = 29, Name = "Name 29" },
                    new { ID = 30, Name = "Name 30" },
                }.Where(e);
            }

        }

        public class Grid1D : UilController, IUilEntitiesSource
        {
            #region IUilEntitiesSource Members

            static readonly DbFieldID.List _KeyFields = new DbFieldID.List("ID");
            public DbFieldID.List KeyFields { get { return _KeyFields; } }
            public DbFieldID.List SortFields { get { return null; } }
            public DbFieldID.List GroupFields { get { return null; } }

            public bool? CanInsert { get { return false; } }
            public bool? CanEdit { get { return false; } }
            public bool? CanDelete { get { return false; } }
            public bool? IsLocal { get { return null; } }
            public int? PageSize { get { return 20; } }

            #endregion

            public IEnumerable GetData(QueryArgs e)
            {
                return new[]
                {
                    new { ID = 1, Name = "Detail Name  1" },
                    new { ID = 2, Name = "Detail Name  2" },
                    new { ID = 3, Name = "Detail Name  3" },
                    new { ID = 4, Name = "Detail Name  4" },
                    new { ID = 5, Name = "Detail Name  5" },
                    new { ID = 6, Name = "Detail Name  6" },
                    new { ID = 7, Name = "Detail Name  7" },
                    new { ID = 8, Name = "Detail Name  8" },
                    new { ID = 9, Name = "Detail Name  9" },
                    new { ID = 10, Name = "Detail Name 10" },
                    new { ID = 21, Name = "Detail Name 21" },
                    new { ID = 22, Name = "Detail Name 22" },
                    new { ID = 23, Name = "Detail Name 23" },
                    new { ID = 24, Name = "Detail Name 24" },
                    new { ID = 25, Name = "Detail Name 25" },
                    new { ID = 26, Name = "Detail Name 26" },
                    new { ID = 27, Name = "Detail Name 27" },
                    new { ID = 28, Name = "Detail Name 28" },
                    new { ID = 29, Name = "Detail Name 29" },
                    new { ID = 30, Name = "Detail Name 30" },
                }.Where(e);
            }


        }


    }


}